#include <bits/stdc++.h>
using namespace std;

int N;
int a[200005];

long long quick_pow(int a,int n,int m){
	long long temp = 1;
	for (;n;n>>=1){
		if (n&1) temp = 1ll*temp*a%m;
		a = 1ll*a*a%m;
	}
	return temp;
}

int main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	cin>>N;
	for (int i = 1;i<=N;i++){
		int n,ans = 0;
		cin>>n;
		for (int j = 1;j<=n;j++){
			cin>>a[j];
		}
		sort(a+1,a+1+n);
		for (int j = 2;j<=n;j++){
			if (a[j] == a[j-1]) {
				ans +=a[j];
			}
		}
		cout<<ans<<endl;
		memset(a,0,sizeof(a));
	}
	return 0;	
}
